package com.etc.yzrnx.library.service.impl;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.etc.yzrnx.library.bean.Reader;

public class ResultlListReaderTableModel extends AbstractTableModel {

	private List<Reader> readers;
	private String[] names;
	public Vector columnHeaders;
	public Vector tableData;
	public int i;

	public ResultlListReaderTableModel(List<Reader> readers, String[] names) {
		super();
		this.readers = readers;
		this.names = names;

		Vector rowData ;

		columnHeaders = new Vector(names.length);
		tableData = new Vector();
		for (i = 1; i <= names.length; i++) {
			columnHeaders.addElement(names[i - 1]);
		}

		Iterator<Reader> it = readers.iterator();
		while (it.hasNext()) {
			Reader reader = it.next();

			rowData=new Vector<>(names.length);
			
			
			rowData.addElement(reader.getR_id());
			rowData.addElement(reader.getR_name());
			rowData.addElement(reader.getR_tel());
			rowData.addElement(reader.getR_department());
			rowData.addElement(reader.getR_pwd());
			rowData.addElement(reader.getR_mail());
			rowData.addElement(reader.getR_booknumberlimit());
			rowData.addElement(reader.getR_ableread());


			tableData.addElement(rowData);
		}
	}

	public int getColumnCount() {
		return columnHeaders.size();
	}

	public int getRowCount() {
		return tableData.size();
	}

	public Object getValueAt(int row, int column) {
		Vector rowData = (Vector) (tableData.elementAt(row));
		return rowData.elementAt(column);
	}

	public boolean isCellEditable(int row, int column) {
		return false;
	}

	public String getColumnName(int column) {
		return (String) (columnHeaders.elementAt(column));
	}

}
